//
//  ViewController.m
//  tmpTableTest
//
//  Created by hh on 15/11/23.
//  Copyright © 2015年 hh. All rights reserved.
//

#import "ViewController.h"
#import "inputViewController.h"

@interface ViewController () <InputFinishDelegate>
{
    NSArray *data;
    NSArray *tels;
    NSIndexPath *curIndexPath;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    data = @[
             @"李梦杰",
             @"尹彬",
             @"苏夏洪",
             @"张学景",
             @"钟家学",
             @"邓志任"
             ];
    tels = @[
             @"13312345678",
             @"13487654321",
             @"13567386444",
             @"13666667777",
             @"13777776666",
             @"13888889999"
             ];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.text = data[indexPath.row];
    cell.detailTextLabel.text = tels[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    curIndexPath = indexPath;
    inputViewController *con = [[inputViewController alloc] initWithStyle:UITableViewStyleGrouped];
    con.tel = tels[indexPath.row];
    con.delegate = self;
    [self.navigationController pushViewController:con animated:YES];
}

- (void)inputFinished:(NSString *)text
{
    NSMutableArray *arr = tels.mutableCopy;
    [arr replaceObjectAtIndex:curIndexPath.row withObject:text];
    tels = arr;
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
